package com.ug.system.entity.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ug.system.entity.vo.SysUserVO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @Author LY
 * @create 2024/7/16 16:17
 * @Description security 用户信息 dto
 */
@Getter
@AllArgsConstructor
public class JwtUserDto implements UserDetails {

    private final SysUserVO user;

    @JsonIgnore
    private final List<GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    @JsonIgnore
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    /**
     * 账户是否未过期,过期无法验证
     */
    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     */
    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     */
    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用,禁用的用户不能身份验证
     */
    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return user.getEnabled() == 1;
    }
}
